/**
 * 
 */
package com.fpt.edu.vn.h2tv.mapper;

import java.util.ArrayList;
import java.util.List;

import com.fpt.edu.vn.h2tv.dao.entity.TbBook;
import com.fpt.edu.vn.h2tv.dto.Book;

/**
 * @author niteha
 *
 */
public final class BookMapper {

	private BookMapper() {}

	public static Book toDTO(TbBook bookPE) {

		if (bookPE == null) {
			return null;
		} else {
			Book bookDTO = new Book();
			bookDTO.setBookId(bookPE.getBooktid().intValue());
			bookDTO.setBookName(bookPE.getBookname());
			bookDTO.setAuthor(bookPE.getAuthor());
			bookDTO.setPrice(bookPE.getPrice().doubleValue());
			bookDTO.setCategoryId(bookPE.getCategoryid().shortValue());
			bookDTO.setPicture(bookPE.getBookImagel());
	
			return bookDTO;
		}
	}

	public static TbBook toPE(Book bookDTO) {

		if (bookDTO == null) {
			return null;
		} else {
			TbBook bookPE = new TbBook();
			bookPE.setBooktid(bookDTO.getBookId());
			bookPE.setBookname(bookDTO.getBookName());
			bookPE.setAuthor(bookDTO.getAuthor());
			bookPE.setPrice(bookDTO.getPrice());
			bookPE.setCategoryid(bookDTO.getCategoryId());
			bookPE.setBookImagel(bookDTO.getPicture());

			return bookPE;
		}
	}

	public static List<TbBook> toPEList(List<Book> bookDTOList) {

		if (bookDTOList == null) {
			return new ArrayList<TbBook>(0);
		} else {
			List<TbBook> bookDAOList = new ArrayList<TbBook>(bookDTOList.size());
			TbBook bookDAO;
			for (Book bookDTO : bookDTOList) {
				bookDAO = BookMapper.toPE(bookDTO);
				bookDAOList.add(bookDAO);
			}

			return bookDAOList;
		}
	}

	public static List<Book> toDTOList(List<TbBook> bookPEList) {

		if (bookPEList == null) {
			return new ArrayList<Book>(0);
		} else {
			List<Book> bookDTOList = new ArrayList<Book>(bookPEList.size());
			Book bookDTO;
			for (TbBook bookPE : bookPEList) {
				bookDTO = BookMapper.toDTO(bookPE);
				bookDTOList.add(bookDTO);
			}

			return bookDTOList;
		}
	}
}
